package com.tanhua.server.test;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.tanhua.dubbo.api.MovementApi;
import com.tanhua.model.db.Movement;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @auther : 白月尘
 * @date : 14:42  2021/10/21
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class RandomMovementUtils {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @DubboReference
    private MovementApi movementApi;

    @Test
    public void init() {
        List<Movement> list = movementApi.randomMovements(20);
        List<ObjectId> ids = CollUtil.getFieldValues(list, "id", ObjectId.class);
        String str = StrUtil.join(",", ids);
        redisTemplate.opsForValue().set("MOVEMENTS_RECOMMEND_106",str);
    }
}